
export function generateUniqueId(type) {
  if(type === 'start-node') {
    return 'start-node';

  } else if(type === 'end-node') {
    return 'end-node';
  }
  // 获取当前时间戳（毫秒级）
  let id = '';
  // 首位：1-9（避免前导零）
  id += Math.floor(Math.random() * 9 + 1);
  // 后续18位：0-9
  for (let i = 0; i < 18; i++) {
    id += Math.floor(Math.random() * 10);
  }
  return id;
}

export function getNodeWidth(node) {
  let widths = {
    'start-node': 420,
    'llm-node': 320,
    'judge-node': 668,
    'http-node': 568,
    'question-node': 568,
    'ai-dialogue-node': 568,
    'knowledge-base-node': 568,
    'end-node': 420,
    'specify-reply-node': 420
  }

  return widths[node.type] || 568
}

export function getNodeHeight(node) {
  if (node.type == 'start-node') {
    return 274
  }

  if (node.type == 'llm-node') {
    return 140
  }

  // if (node.type == 'knowledge-base-node') {
  //   return getKnowledgeBaseNodeHeight(node)
  // }

  if (node.type == 'question-node') {
    return 502
  }

  if (node.type == 'ai-dialogue-node') {
    return 674
  }

  if (node.type == 'end-node') {
    return 86
  }

  if (node.type == 'variable-assignment-node') {
    return 130
  }

  if (node.type == 'specify-reply-node') {
    return 312
  }
  if (node.type == 'explain-node') {
    return 152
  }
  return 800
}
const hexList = [];
for (let i = 0; i <= 15; i++) {
  hexList[i] = i.toString(16);
}

export function buildUUID() {
  let uuid = '';
  for (let i = 1; i <= 36; i++) {
    if (i === 9 || i === 14 || i === 19 || i === 24) {
      uuid += '-';
    } else if (i === 15) {
      uuid += 4;
    } else if (i === 20) {
      uuid += hexList[(Math.random() * 4) | 8];
    } else {
      uuid += hexList[(Math.random() * 16) | 0];
    }
  }
  return uuid.replace(/-/g, '');
}

let unique = 0;
export function buildShortUUID(prefix = '') {
  const time = Date.now();
  const random = Math.floor(Math.random() * 1000000000);
  unique++;
  return prefix + '_' + random + unique + String(time);
}
